﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ComponentModel.Composition;

using NuMetaheuristics;

namespace NuMetaheuristics.Operators.Value
{
    /// <summary>
    /// Appl the abs function to a double value.
    /// </summary>
    [Export(typeof(IUnaryOperator<double>))]
    [DataContract(Namespace = "http://numetaheuristics.codeplex.com/schemas")]
    public class DoubleAbsValue : IUnaryOperator<double>
    {
        public void Operate(ref double operand)
        {
            operand = Math.Abs(operand);
        }
    }

    /// <summary>
    /// Appl the abs function to an int value.
    /// </summary>
    [Export(typeof(IUnaryOperator<int>))]
    [DataContract(Namespace = "http://numetaheuristics.codeplex.com/schemas")]
    public class IntegerAbsValue : IUnaryOperator<int>
    {
        public void Operate(ref int operand)
        {
            if (operand == Int32.MinValue)
            {
                operand = Int32.MaxValue;
            }
            else
            {
                operand = Math.Abs(operand);
            }
        }
    }
}
